/**
 * 
 */
package com.application.DataProvider;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author TAI
 *
 */
public class MD5 {
	
	/**
	 * Hàm dùng mã hóa chuỗi thành dạng MD5
	 * @param s chuỗi cần mã hóa hash
	 * @return chuỗi sau khi mã hóa MD5
	 */
	public static String Md5Coding(String s)
	{
		MessageDigest m = null;
		try {
			m = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	    m.update(s.getBytes(),0,s.length());
	    String md5 = new BigInteger(1,m.digest()).toString(16);
	    
	    if (md5.length() == 31) {
	    	md5 = "0" + md5;
	    }
	    return md5;
	}

}
